/*
 * Tic-Tac-Toe - Turn-based strategy game
 * Copyright 2008, 2009 Shayne Riley and Paul Maseberg
 *
 * Tic-Tac-Toe is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Tic-Tac-Toe is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Tic-Tac-Toe.  If not, see <http://www.gnu.org/licenses/>
 * or write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * To contact the authors on questions or issues regarding the license,
 * you may send an email to <shayner at gmail dot com>
 */

#ifndef GAMEBOARD_H_
#define GAMEBOARD_H_


class GameBoard {

public:

	enum Marker { X=-1, UNSET=0, O=1 };
	enum Difficulty {EASY, HARD};


	GameBoard(Difficulty level = HARD, Marker humanPlayer = X);

	virtual ~GameBoard();

	/**
	 * Get the state of the board at a given location.
	 * @param row Row location.
	 * @param column Column location.
	 * @return The marker at that location.
	 */
	Marker getMarker(int row, int column);

	/**
	 * Human player makes a move
	 * @param row Row of move location.
	 * @param column Column of move location.
	 * @return True if possible false otherwise.
	 */
	bool makeMove(int row, int column);

	/**
	 * Computer makes a move.
	 * @return True if successfully false otherwise.
	 */
	bool makeMove();

	/**
	 * Checks to see if the game is over and if it is will will set
	 * winner to the correct state.
	 * @return True if the game is over false otherwise.
	 */
	bool isGameOver();

	/**
	 * Returns the winner. If called be isGameOver() returns true the result
	 * will always be Marker::UNSET.
	 * @return The winning player or Marker::UNSET if a tie or game not over.
	 */
	int winner() const;


private:

    int checkForWinner(Marker player);

    void hardAI();

    bool threeInARow(Marker player);

    void randomAI();

	/// The gird that holds the state of the game board.
	Marker mGameBoard[3][3];

	/// How hard the play is.
	Difficulty mLevel;

	/// Who the human player is.
	Marker mHumanPlayer;

	/// Who the winner is.
	int mWinner;


};

#endif /* GAMEBOARD_H_ */
